<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="region" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbent">
              <a-input v-model="model.sffbent" placeholder="请输入region"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="据点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbsite">
              <a-input v-model="model.sffbsite" placeholder="请输入据点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbdocdt">
              <j-date placeholder="请选择单据日期"  v-model="model.sffbdocdt" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工单单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb005">
              <a-input v-model="model.sffb005" placeholder="请输入工单单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报工料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb029">
              <a-input v-model="model.sffb029" placeholder="请输入报工料号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imaal003">
              <a-input v-model="model.imaal003" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报工组别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb024">
              <a-input v-model="model.sffb024" placeholder="请输入报工组别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报工班别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb004">
              <a-input v-model="model.sffb004" placeholder="请输入报工班别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机器编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb010">
              <a-input v-model="model.sffb010" placeholder="请输入机器编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划机时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbud014">
              <a-input v-model="model.sffbud014" placeholder="请输入计划机时"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb015">
              <a-input v-model="model.sffb015" placeholder="请输入机时"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="BOM周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bmaaud012">
              <a-input v-model="model.bmaaud012" placeholder="请输入BOM周期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbud011">
              <a-input v-model="model.sffbud011" placeholder="请输入实际周期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="BOM穴数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bmaaud013">
              <a-input v-model="model.bmaaud013" placeholder="请输入BOM穴数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产穴数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbud012">
              <a-input v-model="model.sffbud012" placeholder="请输入生产穴数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划产能" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffbud015">
              <a-input v-model="model.sffbud015" placeholder="请输入计划产能"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="良品数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb017">
              <a-input v-model="model.sffb017" placeholder="请输入良品数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="sffd002" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffd002">
              <a-input v-model="model.sffd002" placeholder="请输入sffd002"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="la3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="la3">
              <a-input v-model="model.la3" placeholder="请输入la3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="la4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="la4">
              <a-input v-model="model.la4" placeholder="请输入la4"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="la5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="la5">
              <a-input v-model="model.la5" placeholder="请输入la5"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模具编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfaaua001">
              <a-input v-model="model.sfaaua001" placeholder="请输入模具编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sffb023">
              <a-input v-model="model.sffb023" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChWorkReportForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chWorkReport/add",
          edit: "/ch/chWorkReport/edit",
          queryById: "/ch/chWorkReport/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>